﻿<!-- 
// (c) Copyright Webber-Cross Software Ltd.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
-->
    
    <Window xmlns:ui="clr-namespace:WebberCross.BdcModelBuilder.UIControls"  x:Class="WebberCross.BdcModelBuilder.AssemblyTree"
        xmlns:vm="clr-namespace:WebberCross.BdcModelBuilder.ViewModels"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Assembly Tree" Height="300" Width="400" Icon="/WebberCross.BdcModelBuilder;component/gear.ico">

    <Window.Resources>
        <ControlTemplate x:Key="TreeViewItemControlTemplate" TargetType="{x:Type TreeViewItem}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition MinWidth="19" Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <ToggleButton x:Name="Expander" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}">
                    <ToggleButton.Style>
                        <Style TargetType="{x:Type ToggleButton}">
                            <Setter Property="Focusable" Value="False"/>
                            <Setter Property="Width" Value="19"/>
                            <Setter Property="Height" Value="13"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                                        <Border Background="Transparent" Height="13" Width="19">
                                            <Border BorderBrush="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" Height="9" SnapsToDevicePixels="True" Width="9">
                                                <Path x:Name="ExpandPath" Data="M0,2L0,3 2,3 2,5 3,5 3,3 5,3 5,2 3,2 3,0 2,0 2,2z" Fill="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" Margin="1"/>
                                            </Border>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsChecked" Value="True">
                                                <Setter Property="Data" TargetName="ExpandPath" Value="M0,2L0,3 5,3 5,2z"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ToggleButton.Style>
                </ToggleButton>
                <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Column="1" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
                    <ContentPresenter x:Name="PART_Header" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                </Border>
                <ItemsPresenter x:Name="ItemsHost" Grid.ColumnSpan="2" Grid.Column="1" Grid.Row="1"/>
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsExpanded" Value="False">
                    <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
                </Trigger>
                <Trigger Property="HasItems" Value="False">
                    <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
                </Trigger>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="FontWeight" Value="Bold" />
                </Trigger>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="IsSelected" Value="True"/>
                        <Condition Property="IsSelectionActive" Value="False"/>
                    </MultiTrigger.Conditions>
                    <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                </MultiTrigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="40"/>
        </Grid.RowDefinitions>
        
        <TreeView ItemsSource="{Binding Classes}" >
            <TreeView.ItemContainerStyle>
                <Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                    <Setter Property="Template" Value="{StaticResource TreeViewItemControlTemplate}" />
                    <Setter Property="FontWeight" Value="Normal" />
                </Style>
            </TreeView.ItemContainerStyle>

            <TreeView.Resources>

                <HierarchicalDataTemplate DataType="{x:Type vm:ClassViewModel}" ItemsSource="{Binding Children}">
                    <ui:TreeNode Source="Images\Class.png" />
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type vm:MethodViewModel}" ItemsSource="{Binding Children}">
                    <ui:TreeNode Source="Images\Method.png" />
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type vm:PropertyViewModel}" ItemsSource="{Binding Children}">
                    <ui:TreeNode Source="Images\Property.png" />
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type vm:ParameterViewModel}" ItemsSource="{Binding Children}">
                    <ui:TreeNode Source="Images\Parameter.png" />
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type vm:TypeViewModel}" ItemsSource="{Binding Children}">
                    <ui:TreeNode Source="Images\Type.png" />
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type vm:ConstructorViewModel}" ItemsSource="{Binding Children}">
                    <ui:TreeNode Source="Images\Method.png" />
                </HierarchicalDataTemplate>

                <!-- Folders -->
                <HierarchicalDataTemplate DataType="{x:Type vm:PropertyFolderViewModel}" ItemsSource="{Binding Children}">
                    <ui:TreeNode Source="Images\Folder.png" />
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type vm:MethodFolderViewModel}" ItemsSource="{Binding Children}">
                    <ui:TreeNode Source="Images\Folder.png" />
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type vm:ReturnTypeFolderViewModel}" ItemsSource="{Binding Children}">
                    <ui:TreeNode Source="Images\Folder.png" />
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type vm:ParameterFolderViewModel}" ItemsSource="{Binding Children}">
                    <ui:TreeNode Source="Images\Folder.png" />
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type vm:ConstructorFolderViewModel}" ItemsSource="{Binding Children}">
                    <ui:TreeNode Source="Images\Folder.png" />
                </HierarchicalDataTemplate>

            </TreeView.Resources>

        </TreeView>
        
        <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center">
            <Button Width="80" Margin="5" Content="OK" IsDefault="True" Click="Button_Click" />
            <Button Width="80" Margin="5" Content="Cancel" IsCancel="True" />
        </StackPanel>
    </Grid>
</Window>
